package com.yh.controller.api;

import com.yh.anno.LoginAuthentication;
import com.yh.service.CinemaService;
import com.yh.utils.Constants;
import com.yh.vo.ResponseVO;
import com.yh.vo.ScheduleVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yuhuan
 * @date 2022/01/13
 */
@RestController
@RequestMapping("/api/schedule")
public class ScheduleWeb {
    @DubboReference(check = false)
    private CinemaService cinemaService;

    /**
     * 根据场次信息的ID查询场次详情信息
     * 服务地址 http://hocalhost:8080/api/schedule/detail/id
     */
    @RequestMapping("/detail/id")
    @LoginAuthentication
    public ResponseVO findScheduleDetailById(int scheduleId) {
        ScheduleVO scheduleVO = cinemaService.findScheduleDetailById(scheduleId);
        return ObjectUtils.isEmpty(scheduleVO) ? ResponseVO.buildSuccessInstance(Constants.ResponseDataState.NULL_RESULT) :
                ResponseVO.buildSuccessInstance(scheduleVO);
    }

    /**
     * 根据影片ID、影院ID和播放的开始日期查询当天的所有场次详情（场次基本信息+影厅详情+语言版本）
     * 服务地址 http://localhost:8080/api/schedule/details/by/mid/cid/date
     */
    @RequestMapping("/details/by/mid/cid/date")
    public ResponseVO findScheduleDetailsByMovieIdAndCinemaIdAndStartDate(int movieId, int cinemaId, int dateSign) {
        List<ScheduleVO> scheduleVos = cinemaService.findScheduleDetailsByMovieIdAndCinemaIdAndStartDate(movieId, cinemaId, dateSign);
        return ObjectUtils.isEmpty(scheduleVos) ? ResponseVO.buildSuccessInstance(Constants.ResponseDataState.NULL_RESULT) :
                ResponseVO.buildSuccessInstance(scheduleVos);
    }
}
